/*
 * @lc app=leetcode.cn id=739 lang=javascript
 *
 * [739] 每日温度
 */

// @lc code=start
/**
 * @param {number[]} temperatures
 * @return {number[]}
 */
var dailyTemperatures = function(temperatures) {
  let statck = [];
  let ret = new Array(temperatures.length).fill(0);

  for (let i = 0; i < temperatures.length; i++) {
    while(statck.length && temperatures[i] > temperatures[statck[statck.length - 1]]) {
      let index = statck.pop();
      ret[index] = i - index;
    }
    statck.push(i);
  }
  return ret;
};
// @lc code=end

